package com.jule.miaozhuapc.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jule.miaozhuapc.dao.AdvertDao;
import com.jule.miaozhuapc.dao.GameRecordDao;
import com.jule.miaozhuapc.dao.PayDao;
import com.jule.miaozhuapc.dao.UserDao;
import com.jule.miaozhuapc.dao.WawaDao;
import com.jule.miaozhuapc.domain.WawaGameRecord;
import com.jule.miaozhuapc.domain.WawaPay;
import com.jule.miaozhuapc.domain.WawaUser;
import com.jule.miaozhuapc.domain.WawaWawa;
import com.jule.miaozhuapc.dto.GameRecordDto;
import com.jule.miaozhuapc.service.AdvertService;
import com.jule.miaozhuapc.service.GameRecordService;
import com.jule.miaozhuapc.service.PayService;

@Service
@Transactional
public class GameRecordServiceImpl implements GameRecordService{
	
	@Autowired
	GameRecordDao gameRecordDao;
	@Autowired
	WawaDao wawaDao;
	
	@Override
	public List<GameRecordDto> findAllByUserId(Long userId, Boolean type, int page, int size) {
	
		List<GameRecordDto> gameRecordDtos = new ArrayList<>();
		//默认返回成功记录
		type = type != null ? type : true;
		List<WawaGameRecord> gameRecords = gameRecordDao.findAllByUserId(userId, type, page, size);
		if (gameRecords.size() > 0) {
			for (WawaGameRecord gameRecord : gameRecords) {
				WawaWawa wawa = wawaDao.findById(gameRecord.getWawaId());

				GameRecordDto gameRecordDto = 	new GameRecordDto();
				gameRecordDto.setAddTime(gameRecord.getAddTime());
				gameRecordDto.setId(gameRecord.getId());
				gameRecordDto.setWawaImg(wawa.getImg());
				gameRecordDto.setWawaName(wawa.getName());
				gameRecordDto.setIsSucccess(gameRecord.getIsSuccess());
				gameRecordDtos.add(gameRecordDto);
			}
		}
		return gameRecordDtos;
	}
}
